<template>
    <div>
        <el-row>
            <el-col :span="24" class="base-mian-cell"  v-if="reportFlag">
                <div class="base-mian-cell-title clearfix">
                    <div class="left fl">
                        <span class="line">|</span>
                        <span class="tips">补充告知书一览</span>
                    </div>
                    <div class="right fr" @click="chanegView">
                        <i class="el-icon-circle-close"></i>
                    </div>
                </div>
                <div class="check-main">
                      <button class="check-info" v-if="reports.length>0" @click="showImageList">查看详情</button>
                </div>
                <div class="base-mian-cell-main">
                    <el-table
                            :data="reports"
                            style="width: 100%"
                            @selection-change="handleSelectionChange">
                        <el-table-column
                                type="selection"
                                width="55">
                        </el-table-column>
                        <el-table-column prop="policyNo" label="保单号" min-width="120" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column  prop="docTyp" label="单证名称" min-width="120" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column prop="scanDate" label="扫描日期" min-width="160" show-overflow-tooltip>
                        </el-table-column>
                        <el-table-column prop="busiType" label="资料归属" min-width="120" show-overflow-tooltip>
                            <template slot-scope="scope">
                                {{scope.row.busiType | busiTypePipe}}
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
            </el-col>
        </el-row>

        <el-row>
            <el-col :span="24">
                <div class="pagination">
                    <el-pagination
                            background
                            v-if='paginations.total > 0'
                            :page-sizes="paginations.pageSizes"
                            :page-size="paginations.pageSize"
                            :layout="paginations.layout"
                            :total="paginations.total"
                            :current-page='paginations.pageIndex'
                            @current-change='handleCurrentChange'
                            @size-change='handleSizeChange'>
                    </el-pagination>
                </div>
            </el-col>
        </el-row>

        <!--影像列表-->
        <cdfs-image-list :drawer="showImageFlag" :policyNO="showImagePolicy" :docType="docType" @close="hideImageList"></cdfs-image-list>

    </div>
</template>
<script>
  import {busiTypePipe} from '@/pipe/comPipe';
  import CdfsImageList from "@/page/common/cdfsImageList";
  import {customerPolicyNos} from "@/api/underwriting/uw";
  import constant from '@/utils/constant';
  import {ImageQuerySearch} from "@/api/taskCenter/taskCommon";
  import uwLoadJs from '@/utils/uwLoad';
  import appName from '@/api/appName';
export default {
    data(){
        return{
          showImageFlag:false,
          showImagePolicy:'',
          docType:'新契约告知书,补充告知声明书,`新契约告知书,`补充告知声明书',
          multipleSelection:[],
          reports: [],
          paginations: {
            total: 0,        // 总数
            pageIndex: 1,  // 当前位于哪页
            pageSize: 10,   // 1页显示多少条
            pageSizes: [5, 10, 15, 20],  //每页显示多少条
            layout: "total, sizes, prev, pager, next, jumper"   // 翻页属性
          },

            initDataTimeOut:null,
        }
    },
    props:{
        reportFlag:{
            type: Boolean,
            default: false
        },
      clntnum:{
        type: String,
        default:""
      }
    },
    destroyed() {
      clearTimeout(this.initDataTimeOut)
    },
    components: {
    "cdfs-image-list":CdfsImageList
  },
    methods:{
      handleCurrentChange(page) {
        this.paginations.pageIndex = page;
        this.initData();
      },
      handleSizeChange() {
        this.paginations.pageSize = pageSize;
        this.initData();
      },

        chanegView(){
            this.$emit('subReportFlag',false)
        },
      showImageList() {
        debugger
        if(this.multipleSelection.length>0){
          let applnum = "";
          let docType = "";
          this.multipleSelection.forEach(item=>{
            applnum = applnum+item.policyNo+",";
          })
          if(applnum.indexOf(",")!=-1){
            applnum = applnum.substring(0,applnum.length-1);
          }
          this.showImagePolicy = applnum;
          this.showImageFlag = true;
        }else{
          this.$message({
            message: "请选择需要查看的保单！",
            type: 'error'
          });
        }

      },
      hideImageList() {
        this.showImagePolicy = '';
        this.showImageFlag = false;
      },
      handleSelectionChange(val) {
        this.multipleSelection = val;
      },
       initData(){
        let that = this;
        let pagesize = that.paginations.pageSize;
        let pageIndex = that.paginations.pageIndex;
         let userId = "";
         if(sessionStorage.getItem("loginForm")){
           let loginForm = JSON.parse(sessionStorage.getItem("loginForm"));
           userId=loginForm.userName;
         }
         let params = {
           "clntnum": this.clntnum
         }
         that.$emit('showLoading',true);
         this.initDataTimeOut = setTimeout(function () {
           debugger
           let policyNos="";
           let url = appName.NEWUNDR + '/unipnd/euab/getChdrnumByClntnum';
           let res = uwLoadJs.ajaxRequest(params,url);
           if(res==null){

           }else if(res.data!=null){
             if(res.data.length>0){
               res.data.forEach(item=>{
                 policyNos = policyNos +item+",";
               })
             }
             if(policyNos.indexOf(",")!=-1){
               policyNos = policyNos.substring(0,policyNos.length-1);
             }
           }
             // policyNos = "02291226";
             console.log("policyNos:"+policyNos)
           that.reports = [];
             if(policyNos!=""){
               let docType = that.docType;
               let params1 = {
                 "begintime": "",
                 "birthday": "",
                 "branchCode": "",
                 "busiNO":  "",
                 "busiType": "NB",
                 "comCode": "",
                 "docType": docType,
                 "doflag": "caseimage",
                 "groupNO": "",
                 "imgsort": "",
                 "imgsortorder1": "",
                 "imgsortorder2": "",
                 "imgsortorder3": "",
                 "insured": "",
                 "isNoCaseno": "",
                 "isPrint": "",
                 "policyer": "",
                 "policyNO": policyNos ? policyNos : "",
                 "policyno16": "",
                 "productType": "",
                 "serno": "",
                 "stockID": "",
                 "sproductType": "",
                 "spurview": "query",
                 "stype": "general"
               }
               ImageQuerySearch(params1, userId, pagesize, pageIndex).then(res => {
                 if (res.resultCode == constant.SUCCESS && res.resBody) {
                   if (res.strDoFlag == "image" || res.strDoFlag == "caseimage") {
                     that.paginations.total = res.resBody.total;
                     for (var i = 0; i < res.resBody.imageList.length; i++) {
                       const obj = {
                         serno: res.resBody.imageList[i].serno,
                         docTyp: res.resBody.imageList[i].docTyp,
                         stockID: res.resBody.imageList[i].stockID,
                         groupNo: res.resBody.imageList[i].groupNo,
                         scanDate: res.resBody.imageList[i].scanDate,
                         scanTime: res.resBody.imageList[i].scanTime,
                         subbusitype: res.resBody.imageList[i].subbusitype,
                         isPrint: res.resBody.imageList[i].isPrint,
                         remark: res.resBody.imageList[i].remark,
                         busiType: res.resBody.imageList[i].busiType,
                         itemid: res.resBody.imageList[i].itemid,
                         policyNo: res.resBody.imageList[i].policyNo,
                         busiNo: res.resBody.imageList[i].busiNo,
                         productType: res.resBody.imageList[i].productType,
                         ishcprint: res.resBody.imageList[i].ishcprint,
                         version: res.resBody.imageList[i].version,
                         agentNo: res.resBody.imageList[i].agentNo,
                         updateflag: res.resBody.imageList[i].updateflag
                       }
                       that.reports.push(obj);
                     }
                   }
                 }

               }).catch(err => {
                 that.$emit('showLoading',false);
               })
             }
             that.$emit('showLoading',false);
         },100)

       },
    },
  created() {
      debugger
    this.initData();
  },
  filters:{
    busiTypePipe(value){
      return busiTypePipe(value);
    }
  }
}
</script>
<style lang="less" scoped>

</style>